import json1 from './data/data.json';
import { saveAs } from 'file-saver';

var express = require('express');

var app = express();

app.use(express.json()); // for parsing application/json
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

export default {
  'GET /api/data': json1,
  'POST /api/postData': (req, rsp, next) => {
    rsp.setHeader('Access-Control-Allow-Origin', '*');
    rsp.end('ok');
    const reqBody = req.body;
    const data = reqBody.data;
    const fileName = reqBody.name;
    console.log(reqBody);
    saveAs(data, './data/postData/' + fileName);
  },
};
